﻿/*
 * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
 * for more information concerning the license and the contributors participating to this project.
 */

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
using System.Security.Claims;
using static ZeroFramework.IdentityServer.API.Infrastructure.Authentication.GitHub.GitHubAuthenticationConstants;

namespace ZeroFramework.IdentityServer.API.Infrastructure.Authentication.GitHub;

/// <summary>
/// Defines a set of options used by <see cref="GitHubAuthenticationHandler"/>.
/// </summary>
public class GitHubAuthenticationOptions : OAuthOptions
{
    public GitHubAuthenticationOptions()
    {
        ClaimsIssuer = GitHubAuthenticationDefaults.Issuer;
        CallbackPath = GitHubAuthenticationDefaults.CallbackPath;

        AuthorizationEndpoint = GitHubAuthenticationDefaults.AuthorizationEndpoint;
        TokenEndpoint = GitHubAuthenticationDefaults.TokenEndpoint;
        UserInformationEndpoint = GitHubAuthenticationDefaults.UserInformationEndpoint;

        ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
        ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
        ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
        ClaimActions.MapJsonKey(Claims.Name, "name");
        ClaimActions.MapJsonKey(Claims.Url, "url");
    }

    /// <summary>
    /// Gets or sets the domain name to use if using a GitHub Enterprise on-premises deployment.
    /// </summary>
    public string? EnterpriseDomain { get; set; }

    /// <summary>
    /// Gets or sets the address of the endpoint exposing
    /// the email addresses associated with the logged in user.
    /// </summary>
    public string UserEmailsEndpoint { get; set; } = GitHubAuthenticationDefaults.UserEmailsEndpoint;
}
